#!/bin/bash
valgrind --leak-check=full --show-reachable=yes --error-limit=no --suppressions=../valgrind-supp/./valgrind-qt.supp --suppressions=../valgrind-supp/./valgrind-misc.supp --gen-suppressions=all --log-file=_memleak.txt -v ./embroidermodder2 "$@"
cat ./_memleak.txt | ../valgrind-supp/./valgrind-create-suppressions.sh > _memleak.supp

MEMORYLEAKS=$(cat "_memleak.txt" | grep "All heap blocks were freed -- no leaks are possible")

echo "=============================="
if [[ -z "$MEMORYLEAKS" ]]; then
    echo $(cat "_memleak.txt" | grep "LEAK SUMMARY:")
    echo $(cat "_memleak.txt" | grep "definitely lost:")
    echo $(cat "_memleak.txt" | grep "indirectly lost:")
    echo $(cat "_memleak.txt" | grep "possibly lost:")
    echo $(cat "_memleak.txt" | grep "still reachable:")
    echo "Review _memleak.txt for more information."
else
    echo "No memory leaks found :D"
fi
echo "=============================="
